package com.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.entity.Visit;

import io.lettuce.core.dynamic.annotation.Param;
import java.util.List;
import java.util.Map;

@Repository
@Mapper
public interface VisitMapper extends BaseMapper<Visit> {

    @Update("update visit set hospital_department = #{hospitalDepartment}, describtion = #{describtion}, bed_number = #{bedNumber}, state = '已处理' where visit_id = #{visitId} and state = '未处理'")
    int updateById(@Param("visit_id") int visitId, @Param("hospital_department") String hospitalDepartment,
            @Param("describtion") String describtion, @Param("bed_number") int bedNumber, @Param("state") String state);

    @Select("SELECT u.start_date, u.end_date, d.price, pd.start_date AS prescription_start_date, pd.end_date AS prescription_end_date FROM usedrug u JOIN prescriptiondetail pd ON u.prescription_detail_id= pd.prescription_detail_id JOIN Drug d ON pd.drug_id= d.drug_id WHERE u.visit_id=#{visitId} AND pd.prescription_detail_id=#{prescriptionDetailId};")
    List<Map<String,Object>> selectOne(int visitId, int prescriptionDetailId);

    @Select("select * from visit where state = #{state}")
    List<Visit> selectUntreated(String state);


}